package rui.game;

import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.swing.*;
import java.awt.*;

/**
 * 面板上的块,抽象二维上的坐标
 * @author 赵睿
 */
@Data
@NoArgsConstructor
public class Chunk extends JButton {

    private int x;

    private int y;

    private Chunk left;

    private Chunk right;

    private Chunk up;

    private Chunk down;

//    private String text;



    /**
     * 颜色
     */
    //TODO work
    private Color color;

    public Chunk nextTo(Chunk left,Chunk right,Chunk up,Chunk down){
        this.left=left;
        this.right=right;
        this.up=up;
        this.down=down;
        return this;
    }


    public Chunk(int x, int y) {
        super("");
        this.setFont(new Font("楷体", Font.BOLD, 20));
        // 设置各个面板的边框
        this.setBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, Color.black));

        this.x = x;
        this.y = y;
    }


    public static double toPosition(int x, int y) {
        if(y<0){
            return -1.0;
        }
        return Double.parseDouble(x + "." + y);
    }

    public static  int getX(double position){
        return (int)position;
    }

    public static  int getY(double position){
        String str=String.valueOf(position).replaceAll("\\d+\\.","");
        return Integer.parseInt(str);
    }



}
